package com.store.practice.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.store.practice.dto.BgDptInsertParam;
import com.store.practice.mapper.BgDepartmentMapper;
import com.store.practice.mapper.BgPositionMapper;
import com.store.practice.mapper.BgStaffMapper;
import com.store.practice.model.*;
import com.store.practice.service.BgDepartmentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BgDepartmentServiceImpl implements BgDepartmentService {
    private static final Logger logger = LoggerFactory.getLogger(BgDepartmentServiceImpl.class);

    @Autowired
    private BgDepartmentMapper departmentMapper;


    @Override
    public int insert(BgDptInsertParam param) {
        BgDepartment department = new BgDepartment();
        BeanUtil.copyProperties(param,department);
        department.setPersonSum(0);
        int i = departmentMapper.insert(department);
        return i;
    }

    @Override
    public int update(Integer id, BgDptInsertParam param) {
        BgDepartmentExample example = new BgDepartmentExample();
        example.createCriteria().andIdEqualTo(id);
        BgDepartment department = new BgDepartment();
        BeanUtil.copyProperties(param,department);
        department.setId(id);
        int i = departmentMapper.updateByExampleSelective(department, example);
        return i;
    }


    @Override
    public List<BgDepartment> list() {
        return departmentMapper.selectByExample(null);
    }

    private BgDepartment getDptById(Integer dptId){
        return departmentMapper.selectByPrimaryKey(dptId);
    }

}
